let urls = 'https://api-beta.bangzuke.com/v1/';
let axios = function(url, type, date) {
  let token = wx.getStorageSync('token');
  return new Promise((resolve, reject) => {
    wx.showToast({title: '加载中', icon: 'loading', duration: 10000});

    wx.request({
      url: urls + url,
      data: date,
      method: type,
      header: {
        'Authorization': token
      },
      success(res) {
        // 登陆过期
        if (res.data.status === 20007 || res.data.status === 20008) {
          wx.removeStorage({
            key: 'token',
            success(res) {
              wx.reLaunch({
                url: '/pages/logs/logs'
              })
            }
          })
          
        }
        resolve(res.data);
      },
      fail(err) {
        reject(err);
      },
      complete() {
        wx.hideToast();
      }
    })
  })
}

module.exports = axios;
